import {useReducer} from "react";

const initLoginInfo = {
  password: null,
  username: null,
}

const USERNAME = "USERNAME"
const PASSWD = "PASSWD"

function LoginByTextReducer(state, action) {
  switch (action.type){
    case USERNAME:
      return {...state, username: action.value}
    case PASSWD:
      return {...state, password: action.value}
    default:
      return state
  }
}

function useLoginByText() {
  const [loginInfo, dispatch] = useReducer(LoginByTextReducer, initLoginInfo)

  return {loginInfo, dispatch}
}

export default useLoginByText